package me.exchange.com.modules.system.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.nutz.ioc.aop.Aop;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;
import java.util.Set;

/**
 * @author Zheng Jie
 * @date 2018-12-17
 */
@Entity
@Getter
@Setter
@Table(name = "sys_menu")
@org.hibernate.annotations.Table(appliesTo = "sys_menu",comment="菜单资源表")
public class Menu implements Serializable {
    /** serialVersionUID*/
	private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(groups = {Update.class})
    @ApiModelProperty(name = "id",value = "ID",required = false)
    private Long id;

    /** 菜单名称*/
    @NotBlank
    @Column(name = "resources_name")
    @ApiModelProperty(name = "resourcesName",value = "菜单名称",required = false)
    private String resourcesName;

    /** 资源编码*/
    @NotBlank
    @Column(name = "resources_code")
    @ApiModelProperty(name = "resourcesCode",value = "资源编码",required = false)
    private String resourcesCode;

    /** 图标 */
    @Column(name = "icon")
    @ApiModelProperty(name = "icon",value = "图标",required = false)
    private String icon;

    /** 类型，目录、菜单、按钮 */
    @Column(name = "type")
    @ApiModelProperty(name = "type",value = "类型 1目录 2菜单 3按钮",required = false)
    private Integer type;

    /** 链接地址*/
    @Column(name = "path")
    @ApiModelProperty(name = "path",value = "链接地址",required = false)
    private String path;

    /** 状态 0关闭 1开启*/
    @Column(name = "status")
    @ApiModelProperty(name = "status",value = "状态 0关闭 1开启",required = false)
    private Boolean status;

    /** 排序*/
    @Column(unique = true,name = "sort")
    @ApiModelProperty(name = "sort",value = "排序",required = false)
    private Long sort = 999L;

    /** 上级菜单ID */
    @Column(name = "parent_id",nullable = false)
    @ApiModelProperty(name = "parentId",value = "上架菜单ID",required = false)
    private Long parentId;

    /** 权限 */
    @Column(name = "permission")
    @ApiModelProperty(name = "permission",value = "权限",required = false)
    private String permission;

    /** 创建人*/
    @Column(name = "c_admin_id")
    @ApiModelProperty(name = "cAdminId",value = "创建人",required = false)
    private Long cAdminId;

    /** 创建时间*/
    @Column(name = "c_admin_time")
    @CreationTimestamp
    @ApiModelProperty(name = "cAdminTime",value = "创建时间",required = false)
    private Timestamp cAdminTime;

    /** 修改人*/
    @Column(name = "u_admin_id")
    @ApiModelProperty(name = "uAdminId",value = "修改人",required = false)
    private Long uAdminId;

    /** 修改时间  */
    @Column(name = "u_admin_time")
    @CreationTimestamp
    @ApiModelProperty(name = "uAdminTime",value = "修改时间",required = false)
    private Timestamp uAdminTime;

    /** 是否删除*/
    @Column(name = "isdel")
    @ApiModelProperty(name = "isdel",value = "是否删除",required = false)
    private Boolean isdel;

   // private String ids;

    @ManyToMany(mappedBy = "menus")
    @JsonIgnore
    private Set<Role> roles;

    public @interface Update {}

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Menu menu = (Menu) o;
        return Objects.equals(id, menu.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
